{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "3c9eb55e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn.linear_model import LogisticRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "fe664094",
   "metadata": {},
   "outputs": [],
   "source": [
    "lines = np.loadtxt('../data/lr_dataset.csv',delimiter=',',dtype=float)\n",
    "x_total = lines[:,:2]\n",
    "y_total = lines[:,2]\n",
    "ratio = 0.7\n",
    "split = int(len(x_total)*ratio)\n",
    "np.random.seed(0)\n",
    "idx = np.random.permutation(len(x_total))\n",
    "x_total = x_total[idx]\n",
    "y_total = y_total[idx]\n",
    "x_train, x_test = x_total[:split], x_total[split:]\n",
    "y_train, y_test = y_total[:split], y_total[split:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "11419164",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[3.14129907, 2.91620111]]), array([0.5518978]))"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log = LogisticRegression(solver='liblinear')\n",
    "log.fit(x_train, y_train)\n",
    "log.coef_, log.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "066b93be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8766666666666667"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_pred = log.predict(x_test)\n",
    "np.mean(y_pred == y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3389ff68",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "younger",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
